﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace MINERP.CustomerManage.DisposePhoto
{
    public partial class FrmModifyHW : Form
    {
        //属性
        public FrmDisposeMain frm { get; set; }
        public string OldUnit { get; set; }
        public double OldHeight { get; set; }
        public double OldWidth { get; set; }
        public FrmModifyHW()
        {
            InitializeComponent();
        }

        private void FrmModifyHW_Load(object sender, EventArgs e)
        {
            if (OldUnit == "HWin")
            {
                cbUnit.Text = "英寸";
                txtHeight.Text = string.Format("{0:0.##}", OldHeight);
                txtWidth.Text = string.Format("{0:0.##}", OldWidth);
            }
            else
            {
                cbUnit.Text = "厘米";
                txtHeight.Text = string.Format("{0:0.##}", OldHeight * 2.54);
                txtWidth.Text = string.Format("{0:0.##}", OldWidth * 2.54);
            }
            btnOk.Focus();
        }

        private void btnOk_Click(object sender, EventArgs e)
        {
            double newHeight = 0;
            double newWidth = 0;
            try
            {
                newHeight = Convert.ToDouble(txtHeight.Text.Trim());
                newWidth = Convert.ToDouble(txtWidth.Text.Trim());
            }
            catch
            {
                MessageBox.Show("高宽不符合要求，请重新输入！", "确定", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                return;
            }
            if (newHeight <= 0 || newWidth <= 0)
            {
                MessageBox.Show("高宽不符合要求，请重新输入！", "确定", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                return;
            }
            if (cbUnit.Text == "厘米")
            {
                newHeight = newHeight / 2.54;
                newWidth = newWidth / 2.54;
            }
            if (newHeight > OldHeight || newWidth > OldWidth)
            {
                MessageBox.Show("尺寸只能裁小，不能增大", "确定", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                return;
            }
            OldHeight = newHeight;
            OldWidth = newWidth;
            frm.NewHeight = newHeight;
            frm.NewWidth = newWidth;
            DialogResult = DialogResult.OK;
            this.Close();
        }

        private void btnCancel_Click(object sender, EventArgs e)
        {
            this.Close();
        }

        private void cbUnit_SelectedIndexChanged(object sender, EventArgs e)
        {
            if (cbUnit.Text == "厘米")
            {
                txtHeight.Text = string.Format("{0:0.##}", OldHeight * 2.54);
                txtWidth.Text = string.Format("{0:0.##}", OldWidth * 2.54);
            }
            else
            {
                txtHeight.Text = string.Format("{0:0.##}", OldHeight);
                txtWidth.Text = string.Format("{0:0.##}", OldWidth);
            }
        }
    }
}
